package com.winchain.chainbill.basic.invoice.rx;

import com.shell.bee.invoince.po.InvDfr;
import com.shell.bee.invoince.service.InvDfrService;
import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import com.winchain.chainbill.bill.base.po.CbDct;
import com.winchain.chainbill.bill.biz.Bill;
import com.winchain.chainbill.bill.biz.BillEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class BillInvoiceDfrUploadUpdateSubscriber extends OnErrorNotImplementedSubscriber<BillEvent<? extends Object>> {
	@Autowired
	private InvDfrService invDfrService;

	public void onApplicationEvent(BillEvent<? extends Object> t) {
		Object source = t.getBill().getSource();
		if (source == null) {
			return;
		}
		String dfrState = t.getStringValue("dfrState");
		if (dfrState != null) {
			CbDct dct = (CbDct) source;
			InvDfr invDfr = this.invDfrService.selectByBiz(dct.getDctId(), "1");
			if (invDfr != null) {
				String uploadDate = t.getStringValue("uploadDate");
				String remark = t.getStringValue("remark");
				invDfr.setState(dfrState);
				invDfr.setUploadDate(uploadDate);
				invDfr.setRemark(remark);
				this.invDfrService.updateNotNull(invDfr);
			}
		}
	}
}
